package com.example.demo.service.impl;

import com.example.demo.entity.User;
import com.example.demo.repository.IUserRepostiory;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Created by Hy on 2019/3/1.
 */
@Service
public class UserServiceImpl implements IUserService{
    @Autowired
    private IUserRepostiory iUserRepostiory;
    @Override
    public User getUserById(Integer id) {
        Optional<User> userOptional = iUserRepostiory.findById(id);
        return userOptional.get();
    }

    @Override
    public List<User> findList() {
        return iUserRepostiory.findAll();
    }

    @Override
    public void delUser(Integer id) {
        iUserRepostiory.deleteById(id);
    }

    @Override
    public User saveOrUpdate(User user) {
        return iUserRepostiory.save(user);
    }
}
